home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-06-24 | 1.5 KB | 108 lines | [TEXT/MPCC] |
- // InPoint.cpp
-
- #include "InPoint.h"
-
- #define TIMEOUT 2000
-
-
-
- InPoint::InPoint(
- const char *protocol,
- const char *address,
- short port)
- {
- OSErr err = Open(protocol);
- DNSAddress inAddress;
- InetAddress outAddress;
- TBind inBind = { { 0, sizeof(short)+strlen(address)-1, (UInt8*) &inAddress }, 0};
- TBind outBind = { { sizeof(InetAddress), 0, (UInt8*) &fHisAddress }, 0};
-
-
- if (err)
- throw err;
-
- err = Bind(port);
- if (err)
- throw err;
-
- inAddress.fAddressType = kOTGenericName;
- strcpy(inAddress.fName, address);
-
- err = OTResolveAddress(fEndpoint, &inBind, &outBind, TIMEOUT);
- if (err)
- throw err;
- fHisAddressSize = outBind.addr.len;
-
-
- // make it asynchronous and set up to receive
-
- OTInstallNotifier(fEndpoint, &Notifier, this);
-
- }
-
-
- InPoint::~InPoint()
- {
- }
-
-
-
- pascal void
- InPoint::Notifier(
- void* contextPtr,
- OTEventCode code,
- OTResult result,
- void* cookie)
-
- // *** Called at deferred task time. ***
-
- {
- InPoint* thisPoint = (InPoint*) contextPtr;
- thisPoint->HandleNotify(code, result, cookie);
- }
-
-
- void
- InPoint::HandleNotify(
- OTEventCode code,
- OTResult result,
- void* cookie)
-
- // *** Called at deferred task time. ***
-
- {
- switch (code) {
- case T_DATA:
- GetData();
- break;
-
-
-
- }
- }
-
-
- void
- InPoint::GetData()
-
- {
- while (1) {
- TUnitData uData = {
- { 0, 0, NULL },
- { 0, 0, NULL },
- { 0, sizeof(packetBuffer), (UInt8*) &fPacket },
- };
- OTFlags flags;
-
- OSStatus theErr = OTRcvUData(fEndpoint, &uData, &flags);
- if (theErr == kOTNoDataErr)
- break;
- if (theErr != noErr)
- continue;
-
- // do something with data
-
-
- }
-
- }